<?php
/*
 * Created on 21 janv. 2009
 * Created by Ludovic Reenaers
 * lreenaers@hotmail.com
 */
class BreadCrumbGenerator extends Generator{
	private $catPath = array();
	protected $page = "";
	public function getCategoryPath(){
		return $this->catPath;
	}
	public function prepareData(){
		$this->page = '<div class="breadcrumb">  <span class="left"></span><ul>';
		if($_SESSION["module"]<>"homepage"){
			$home = $this->translator->home;
			$this->page.='<li class="padd"></li><li class="home"><a href="'.$_SESSION['config']->controler.'?/homepage/show/" title="'.$home.'" alt="'.$home.'"><img src="/img/go-home.png"/></a></li>';
			if ($_SESSION["module"]=="document" || $_SESSION["module"]=="category"){
				$DAO = $this->Factory->getCategorieDAO();
				$Bean = $DAO->getById(1);
				$this->page.=$this->browseCategories($Bean);
				if ($_SESSION["module"]=="document"){
					$this->page.="<li><span class='active'>".$_SESSION["docname"]."</span></li>";
				}
			}else{
				$this->page.="<li><span class='active'>".$_SESSION["docname"]."</span></li>";
			}
		}
		$this->page .= '</ul><span class="right"></span></div>';
	}
	public function dump(){

		return $this->page;
	}
	private function browseCategories($cat){
		$page='';
		if($_SESSION["module"]=="category"){
			if($cat->hasChildCategorie((int)$_SESSION["catid"])){
				array_push($this->catPath, $cat->getId());
				if(!$cat->isRoot()){

					$info = $cat->getLabel($_SESSION['langue']);
						
					if((int)$_SESSION["catid"]== $cat->getId()){
						$page.= "<li><span class='active'>".$info."</span></li>";
					}else{
						$page.= '<li><a href="'.$_SESSION['config']->controler.'?/category/show/'.$cat->getId().'/'.$info.'/" title="'.$cat->getTooltip($_SESSION['langue']).'" alt="'.$cat->getTooltip($_SESSION['langue']).'">'.$info.'</a></li>';
					}
				}
				foreach ($cat->getChildCategories() as $tmpcat){
					$page.=$this->browseCategories($tmpcat);
				}
			}
		}elseif ($_SESSION["module"]=="document"){
			if($cat->hasChildDocument((int)$_SESSION["docid"])){
				array_push($this->catPath, $cat->getId());
				if(!$cat->isRoot()){
					//$infos=$cat->getInfos();
					//$info = $infos[0]->getLabel();
					$info = $cat->getLabel($_SESSION['langue']);
					$page.= '<li><a href="'.$_SESSION['config']->controler.'?/category/show/'.$cat->getId().'/'.$info.'/" title="'.$cat->getTooltip($_SESSION['langue']).'" alt="'.$cat->getTooltip($_SESSION['langue']).'">'.$info.'</a></li>';
				}
				foreach ($cat->getChildCategories() as $tmpcat){

					$page.=$this->browseCategories($tmpcat);

				}
			}
		}
		return $page;
	}
}
?>